package com.zq.设计模式23种.结构型模式.适配器模式;

/**
 * @author Jiu
 * @description：TODO
 * @date 2020/11/25   14:30
 **/

//适配者1：电能发动机
class ElectricMotor {
    public void electricDrive() {
        System.out.println("电能发动机驱动汽车！");
    }
}

//适配者2：光能发动机
class OpticalMotor {
    public void opticalDrive() {
        System.out.println("光能发动机驱动汽车！");
    }
}

//目标：发动机
interface Motor {
    public void drive();
}

//电能适配器
class ElectricAdapter implements Motor {
    private ElectricMotor emotor;
    public ElectricAdapter() {
        emotor = new ElectricMotor();
    }
    @Override
    public void drive() {
        emotor.electricDrive();
    }
}

//光能适配器
class OpticalAdapter implements Motor {
    private OpticalMotor omotor;
    public OpticalAdapter() {
        omotor = new OpticalMotor();
    }
    @Override
    public void drive() {
        omotor.opticalDrive();
    }
}


//客户端代码   2500-   1100-300-800 = 2200 +
public class MotorAdapterTest {
    public static void main(String[] args) {
        System.out.println("适配器模式测试：");
        Object opticalAdapter = new OpticalAdapter();
        Motor motor=(Motor)opticalAdapter;
        motor.drive();
        System.out.println("-----------------");
        Object electricAdapter = new ElectricAdapter();
        Motor motor2=(Motor)electricAdapter;
        motor2.drive();
    }
}
